{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "be88eabb",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 29. 计算球体的体积\n",
    "\n",
    "编写函数球体计算公式：(4 * pi * r **3) / 3\n",
    "\n",
    "让默认的r为10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "50c2ba96",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4188.790204786391\n",
      "33510.32163829113\n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "def tiji(r=10):\n",
    "    return (4 * pi * r**3) / 3\n",
    "\n",
    "print(tiji())\n",
    "print(tiji(20))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e46f02f8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "086f013b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fade6c2c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d55fcc5f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cc7e91b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00a8fe61",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "3ea92d04",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 28. 返回类型错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2a4a89de",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "如下这个函数会报错，你能看出来哪里错了吗？怎么修复？\n",
    "\"\"\"\n",
    "def foo(a, b):\n",
    "    return a + b\n",
    "\n",
    "x = foo(2, 3) * 10\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7936a796",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e9403f3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99b8cf21",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a570302b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8612d84",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9a3135e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b4ec04a1",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 27. 写一个函数计算加速度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bd493358",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "写一个函数，计算加速度\n",
    "公式：(v2 - v1) / (t2 - t1)\n",
    "\"\"\"\n",
    "\n",
    "def jiasudu(v1, v2, t1, t2):\n",
    "    return (v2 - v1) / (t2 - t1)\n",
    "\n",
    "jiasudu(0, 20, 0, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "615140b3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bdb0fb6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c474dcc1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78b279c3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dfbd849",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9e1c025",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d59628eb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b33e8c91",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "78f589a8",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 26. 用for循环输出数字1到10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ffb898bb",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "for number in range(1, 101):\n",
    "    print(number)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0719b24",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "966a9a57",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f3d2ea12",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "692645df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aee7ba6d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "caa015df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "375cb370",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 25. 输出所有英文字母a~z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81e438e1",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "怎样输出所有英文字母a~z？\n",
    "\"\"\"\n",
    "import string\n",
    "for letter in string.ascii_lowercase:\n",
    "    print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "604f4e8f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4ad6dbe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f086a7cb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2c2b9d8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3dbf6ea7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "542980e8",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 24. for循环遍历字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee168836",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "问题：怎样遍历输出字典的key和value，输出如下形式？\n",
    "b has value [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n",
    "c has value [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]\n",
    "a has value [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
    "\"\"\"\n",
    "d = dict(\n",
    "    a = list(range(1, 11)), \n",
    "    b = list(range(11, 21)), \n",
    "    c = list(range(21, 31))\n",
    ")\n",
    "\n",
    "for key, value in d.items():\n",
    "    print(key, \"has value\", value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1ea9f56",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5e58fe9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e77726b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3acef4f9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d369d97a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1c383cc5",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 23. 访问字典多层索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e71d146",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "问题：怎样访问key==b的第3个元素？\n",
    "\"\"\"\n",
    "d = dict(\n",
    "    a = list(range(1, 11)), \n",
    "    b = list(range(11, 21)), \n",
    "    c = list(range(21, 31))\n",
    ")\n",
    "import pprint\n",
    "pprint.pprint(d)\n",
    "\n",
    "print(d[\"b\"][2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9cf21411",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "190a147c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7ea45d8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f9518d41",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5c4dde3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c85e7b79",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 22. 格式化字典的输出\n",
    "\n",
    "pprint的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05c0558f",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "构建一个字典，key是a/b/c，value是1~10, 11~20, 21~30\n",
    "然后格式化输出\n",
    "\"\"\"\n",
    "from pprint import pprint\n",
    "d = {\n",
    "    \"a\": list(range(1, 11)),\n",
    "    \"b\": list(range(11, 21)),\n",
    "    \"c\": list(range(21, 31)),\n",
    "}\n",
    "pprint(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "baa3210c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1649a018",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b017f53",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de5fa61c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dfd178df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6717c293",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5db72822",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2248e7ef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d37bb38a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "e219a6b8",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 21. 字典值的过滤\n",
    "\n",
    "字典推导式的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc97d9af",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "移除字典值大于1的所有项\n",
    "\"\"\"\n",
    "\n",
    "d = {\"a\": 1, \"b\": 2, \"c\": 3}\n",
    "\n",
    "d2 = {\n",
    "    key:value\n",
    "    for key, value in d.items()\n",
    "    if value<=1\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c755b0d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "430c0d2a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "255f726d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70a41b18",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42d76528",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3feb3f51",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7fe4989a",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 20. 字典所有值的加和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58cf197e",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "计算下方字典所有值的加和\n",
    "\"\"\"\n",
    "d = {\"a\": 1, \"b\": 2, \"c\": 3}\n",
    "print(sum(d.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01eab9ba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3010cbb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca360b06",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6172ddfe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2dda2aaa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "bba478ae",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 19. 给字典新增键值对"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c8e7de3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "给下面的字典新增一个键值对(c, 3)\n",
    "\"\"\"\n",
    "d = {\"a\": 1, \"b\": 2}\n",
    "d[\"c\"] = 3\n",
    "\n",
    "print(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bd266ad",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "532cd7b3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e07381d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "838ee5f3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d12fc34",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "51f45690",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 18. 访问字典KeyError"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "366354fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "访问不在字典里的Key会发生什么？\n",
    "\"\"\"\n",
    "d = {\"a\": 1, \"b\": 2, \"c\": 3}\n",
    "\n",
    "print(d[\"a\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fccf1be6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2dd58865",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1d3edda",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "296796a0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83c09594",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4124a1bd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "76f03af1",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 17. 字典特定值的加和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85aeff40",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "如下字典，怎样得到 key=a 和 key=b的加和？\n",
    "\"\"\"\n",
    "\n",
    "d = {\"a\": 1, \"b\": 2, \"c\": 3}\n",
    "\n",
    "sum = d[\"a\"] + d[\"b\"]\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "360ce17a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07e5a418",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "945d89cd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32fc2634",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57aaa3c7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2a45ca2a",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 16. 获取字典的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa5c23e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "对于如下字典，怎样访问key=b的值？\n",
    "\"\"\"\n",
    "\n",
    "d = {\"a\":1, \"b\": 2}\n",
    "\n",
    "print(d[\"b\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6db4a33b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69af8782",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "90246c5c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f3f33e9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ee735ad",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "8400d56f",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 15. 创建简单字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5a39b14",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "创建一个字典，key是a和b，对应的值是1和2\n",
    "\"\"\"\n",
    "\n",
    "d1 = {\"a\":1, \"b\":2}\n",
    "print(d1)\n",
    "\n",
    "d2 = dict(a=1, b=2)\n",
    "print(d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f38e7012",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c712474",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cda82208",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ed31e9f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b72ce35",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b0b18dae",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 14. 列表去除重复"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "288d6482",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "怎样将如下列表的重复元素去除\n",
    "\"\"\"\n",
    "a = [\"1\", 1, \"1\", 2]\n",
    "\n",
    "print(list(set(a)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1181292",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c4c416b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83645c3f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4544926d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "967a280f",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 13. 生成字符串列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7520bdb7",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "基于range(1, 21)，生成如下列表\n",
    "\n",
    "['1','2','3','4','5','6','7','8','9','10', \n",
    "'11','12','13','14','15','16','17','18','19','20']\n",
    "\"\"\"\n",
    "\n",
    "my_range = range(1, 21)\n",
    "\n",
    "new_list = [str(i) for i in my_range]\n",
    "\n",
    "print(new_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec3083ac",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e1b4ea8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aeea13c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "0837c4c5",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 12. 生成更大数字序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7073558",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "基于range(1, 21)，生成如下列表\n",
    "\n",
    "[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, \n",
    "110, 120, 130, 140, 150, 160, 170, 180, 190, 200] \n",
    "\"\"\"\n",
    "\n",
    "my_range = range(1, 21)\n",
    "\n",
    "new_list = [i*10 for i in my_range]\n",
    "\n",
    "print(new_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3375b943",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1f5eae5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32cdcdfd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f451d7ff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d0593fd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7e64a7a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01e5e67f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d29aaa68",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 11. 新建数字序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9334a239",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 新建数字列表 1~20，不要一个个数字填写\n",
    "\n",
    "my_range = range(1, 21)\n",
    "print(list(my_range))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "686ee240",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca6f8dcf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0577cfab",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8453378b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "7b4ee4f6",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 10. 挑选序列项"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d34a0721",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 ['a', 'c', 'e', 'g', 'i'] \n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48eb1407",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d2d2b52",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36fb3393",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43d3a691",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "cc03b07f",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 09. 负数索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "caf701b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 ['h', 'i', 'j'] \n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3f559ef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5e16dfc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74f8e709",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc59181f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "c97baff1",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 08. 负数索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec240fe3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 i\n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3921cc2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a47a0835",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4ee492d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4500791e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "d5fec58b",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 07. 序列切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72d4c6c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 ['a', 'b', 'c'] ，能简化写法吗？\n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64a69973",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03598aa1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6db2ddf2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1333b26",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "686e0fed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "1b603648",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 06. 序列切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "add35ec0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 ['d', 'e', 'f'] \n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[3:6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d94ce98",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0746288b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88747948",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b933459",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d2b68a1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a937358",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5d7ffcd8",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 05. 序列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a430493",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 完成代码，输出字母 b\n",
    "\n",
    "letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"]\n",
    "\n",
    "print(letters[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c08c8d0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dbce35da",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1db8f573",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46393e87",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2d7df7f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "500553ce",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a085d7f3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d7c6fab",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6fb760d6",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 04. 类型错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a30f546d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 如下代码会报错，请修复它，实现数字加法\n",
    "a = \"1\"\n",
    "b = 2\n",
    "print(int(a) + b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f149c327",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 03. 比较和赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b3e5c78",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 如下代码会报错，你能看出来为什么吗？\n",
    "a = 1\n",
    "b = 2\n",
    "print(a == b)\n",
    "print(b == c)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1a2637b",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 02. 变量命名规范"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f339f4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 如下代码那里错误了？\n",
    "a = 1\n",
    "_a = 2\n",
    "_a2 = 3\n",
    "2a = 4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ee42898",
   "metadata": {},
   "source": [
    "# Python编程挑战100题\n",
    "# 01. 变量更新"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1be2284f",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 2\n",
    "a = 4\n",
    "a = 6\n",
    "print(a + a + a)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
